package top.aigoo.project01.function;

import org.junit.Ignore;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import top.aigoo.project01.utils.redis.JedisPoolUtil;

/**
 * @Description: 请填写该类完成的功能
 * @Author: Mr.OYSHUO.欧阳大叔  mail:1642302522@qq.com
 * @Version 1.0.0
 * @Date: 2021/9/16 17:05
 */
public class JedisTestFunction {
    @Test
    @Ignore
    public void testFuncion(){
        String host = "39.101.186.230";
        int port = 6379;
        String password = "Luo!#*0126";
        Jedis jedis =null;
        try {
            jedis = new Jedis(host,port);
            jedis.auth(password);
            System.out.println("jedis 连接状态:"+jedis.ping());

            jedis.select(1);
            jedis.set("name","kun");
            String name = jedis.get("name");
            System.out.println("name = " + name);
            //清空数据库
            jedis.flushDB();
            String name2 = jedis.get("name");
            System.out.println("name2 = " + name2);

            String name3 = jedis.get("arealist");
            System.out.println("name3 = " + name3);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (null!=jedis){
                try {
                    jedis.close();
                }catch (Exception e){
                    System.out.println("redis连接关闭失败");
                    e.printStackTrace();
                }
            }
        }

    }

    @Test
    public void testJedisPool(){
        Jedis jedis = JedisPoolUtil.getJedis();
        jedis.set("name", "abel");
        // set 多个key and value
        jedis.mset("name", "abel", "age", "23", "qq", "123244232");
        //age  + 1
        jedis.incr("age");
        System.out.println(jedis.get("name"));
        // delete key
        jedis.del("name");
        jedis.close();
    }
}
